import http from '../../utils/http'

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        type: {
            type: String,
            value: 'apply'
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        lists: [],

        showSn: false,

        expressNum: null
    },

    observers: {
        'type': function (type) {
            this.getOrderList(type)
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        async getOrderList(type) {
            const { userInfo } = getApp().globalData

            let queryParams = {
                sortColumns: 'utime',
                sortType: 'desc',
                memberId: userInfo.id
            }
            if(type == 'apply') {
                queryParams.inStatus = '0,1,2,3,4,5'
            } else if(type == 'finish') {
                queryParams.inStatus = '6'
            }

            let res = await http.get('/api/mall/omsorderreturnapply/list', queryParams)
            this.setData({ lists: res.data })
        },

        /**
         * 填写快递单号
         * @param {*} e 
         */
        async submitExpress(e) {
            const { userInfo } = getApp().globalData
            const { expressNum, postId } = this.data

            let queryParams = {
                memberId: userInfo.id,
                id: postId,
                expressNum
            }

            let res = await http.get('/api/mall/omsorderreturnapply/submitExpress', queryParams)
            if(res.status) {
                this.getOrderList(this.data.type)
            }
        },

        // 监听手机号输入框
        inputMobileListen(e) {
            this.setData({ expressNum: e.detail.value })
        },

        showModifySn(e) {
            let { id } = e.currentTarget.dataset
            this.setData({ showSn: true, postId: id })
        },
        onCancelSn() {
            this.setData({ showSn: false })
        },
    }
})
